<?php

require_once (__DIR__."/MyMemory.php");

class MySqlcon {
	
	protected static $db;
	protected static $memkey = "mysql:connection";
	protected static $host="127.0.0.1";
	protected static $username="root";
	protected static $pwd="terttert";
	protected static $database;
	
	public static function getCon($database="jabberd2") {
		$memkey = self::$memkey . ":" . $database;
		self::$db = MyMemory::get($memkey);
		if (!self::$db) {
			self::$database = $database;
			self::$db = mysql_connect(chop(self::$host), chop(self::$username), chop(self::$pwd)) or die ('Keine DB Verbindung : ' . mysql_error());
			mysql_select_db(self::$database, self::$db) or die ('Kann nicht auf DB zugreifen : ' . mysql_error());
		}
		MyMemory::set($memkey, self::$db);
		return self::$db;
	}
	
	public static function setDatabase($database){
		self::$database = $database;
	}

}